package cn.kgc.mushroomdatabaseprovider.controller;

import cn.kgc.mushroomcommon.pojo.Commodity;
import cn.kgc.mushroomcommon.pojo.Shop;
import cn.kgc.mushroomdatabaseprovider.service.CommodityService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/commodity")
public class commController {

    @Resource
    CommodityService commodityService;

    @RequestMapping("/selectcomm")
    public List<Commodity> selectcomm(){
         List<Commodity> commodities = commodityService.selectAll();
         return commodities;
    }

    @RequestMapping("/selectTop")
    public List<Commodity> selectTop(){
         List<Commodity> commodities = commodityService.selectTopsan();
         return commodities;
    }


    @RequestMapping("/selectByid")
    public List<Commodity> selectByid(@RequestParam("tidcommtype")Integer tidcommtype){
        List<Commodity> commodities = commodityService.selectByTypeId(tidcommtype);
        return commodities;
    }

    @RequestMapping("/select/commodity/by/commOrtypename")
    public List<Commodity> selectCommodityByTitleOrTypeName(@RequestParam("commOrTypeName")String commOrTypeName,
                                                            @RequestParam("tiaojian")Integer tiaojian,
                                                            @RequestParam("smallMoney")String smallMoney,
                                                            @RequestParam("bigMoney")String bigMoney){
        try {
            return commodityService.selectCommodityByTitleOrTypeName(commOrTypeName,tiaojian,smallMoney,bigMoney);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
